package com.sinothk.fc.app.service.impl;

import com.sinothk.fc.app.entity.HomePageDataBean;
import com.sinothk.fc.app.entity.StoreIndexData;
import com.sinothk.fc.app.mapper.AppMapper;
import com.sinothk.fc.app.service.IAppHomeService;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.system.vo.LoginUser;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Description: 门店经营服务表
 * @Author: Liangyt
 * @Date: 2022-09-23
 * @Version: V1.0
 */
@Service
public class AppHomeServiceImpl implements IAppHomeService {

    @Resource
    private AppMapper appMapper;

    @Override
    public HomePageDataBean getHomePageTipData() throws Exception {
        LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        if (loginUser == null || StringUtils.isBlank(loginUser.getStoreId())) throw new Exception("当前用户没有门店id");

        HomePageDataBean homePageData = new HomePageDataBean();
        // 门店指数
        homePageData.setStoreIndexData(getStoreIndex(loginUser.getStoreId()));

        return homePageData;
    }

    /**
     * 统计门店指数
     *
     * @param storeId
     * @return
     */
    private StoreIndexData getStoreIndex(String storeId) {
        return appMapper.getStoreIndex(storeId);
    }
}
